from PIL import Image
import numpy as np
from ctypes import c_ubyte

#图片数组空间
unsigned_char_array = (c_ubyte*15006)()
# 初始化数组元素
unsigned_char_array[0] = 0X00
unsigned_char_array[1] = 0X01
unsigned_char_array[2] = 0X90
unsigned_char_array[3] = 0X01
unsigned_char_array[4] = 0X2C
unsigned_char_array[5] = 0X01


image_path='img/image.bmp'


bitmap_image = Image.open(image_path)

#数组->一维化->8个一组切片->列表化
bit_8list=np.array(bitmap_image).flatten().reshape(-1, 8).tolist()
# print(bit_8list)

for i in range(len(bit_8list)):
    int_list = [int(bit) for bit in bit_8list[i]]
    # 将整数列表转换为二进制字符串
    binary_str = ''.join(str(bit) for bit in int_list)
    # 将二进制字符串转换为十六进制数，保留前缀'0x'
    hex_value_with_prefix = int(binary_str,2)
    print(hex_value_with_prefix)
    unsigned_char_array[6+i]=hex_value_with_prefix

# 创建一个包含5个unsigned char元素的数组




# print(int(unsigned_char_array))